<?php
class App_Tpl_Form_Field_Multiselect extends App_Tpl_Form_Field{

	public function PreparePost($fieldPostData, $params)
	{
		$fieldPostData = (array) $fieldPostData;
		
		$values = (array)$params['values'];
		$resValue = array();
		foreach ($fieldPostData as $postVal)
		{
			foreach ($values as $value => $data)
			{
				if ((is_array($data) && array_key_exists($postVal, $data))
					|| ($value == $postVal))
				{
					$resValue[] = $postVal;
					break;
				}
			}
		}
		
		return $resValue;
	}
	
	public function PrepareOut($fieldData, $params)
	{
		return (array)$fieldData;
	}
	
    protected function RenderField()
    {
    	return $this->render('form/field/_multiselect.phtml');
    }

}